//
//  HomeTableViewCell.m
//  NewYD_iOS
//
//  Created by whlx on 2019/1/27.
//  Copyright © 2019 TxY. All rights reserved.
//

#import "HomeTableViewCell.h"
#import "HomeCollectionViewCell.h"
@interface HomeTableViewCell()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation HomeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self setView];
}

-(void)setView{
    UICollectionViewFlowLayout *lay = [[UICollectionViewFlowLayout alloc]init];
//    layout.minimumLineSpacing = 40;
    
    CGFloat cellSpace = 0.0;
//    CGFloat cellWidth = KScreenWidth/2.0;
    
    lay.itemSize = CGSizeMake(144, 130);//Item size(每个item的大小)
    
    lay.sectionInset = UIEdgeInsetsMake(cellSpace, cellSpace, cellSpace, cellSpace);//某个section中cell的边界范围。
    
//    lay.headerReferenceSize = CGSizeMake(KScreenWidth, 40);//每个section的Header宽高
//    lay.footerReferenceSize = CGSizeMake(KScreenWidth, 0.1);//每个section的Footer宽高
    
    lay.minimumInteritemSpacing = cellSpace;//Inter cell spacing（每行内部cell item的间距）
    lay.minimumLineSpacing = cellSpace;//Line spacing（每行的间距）
    //横向滑动
    lay.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 40, kScreenWidth, 130) collectionViewLayout:lay];
    collectionView.delegate = self;
    collectionView.dataSource = self;
//    collectionView.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:collectionView];
   
    [collectionView registerNib: [UINib nibWithNibName:@"HomeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"HomeCollectionViewCell"];
  
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.didClickItem) {
        self.didClickItem();
    }
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 5;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeCollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"HomeCollectionViewCell" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor clearColor];
//    cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.jpg",indexPath.row+1]];
//    cell.label.text =[NSString stringWithFormat:@"%zd. %@",indexPath.row+1,self.dataSource[indexPath.row]];
    return cell;
}

@end
